package cn.aixuegao.web;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import cn.aixuegao.common.base.controller.BaseController;
import cn.aixuegao.common.constant.LogConstant;
import cn.aixuegao.common.result.ResponseData;
import cn.aixuegao.common.result.ResultMsg;
import cn.aixuegao.model.user.User;
import cn.aixuegao.service.user.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags = "用户常用操作的接口 【比如登陆、注册等】")
@RequestMapping(value = "/user", produces = "application/json;charset=UTF-8")
@RestController
public class UserController extends BaseController {
	private static final Logger logger = LogManager.getLogger(LogConstant.USER_LOG);

	@Autowired
	private UserService userService;
	
	@CrossOrigin
	@ApiOperation(value = "登陆")
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	@ApiImplicitParams(value = {
			@ApiImplicitParam(name = "mobilePhone", value = "手机号码", required = true, paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "passWord", value = "密码", required = true, paramType = "query", dataType = "String") })
	public ResponseData testmapper(@RequestParam(value = "mobilePhone", required = false) String mobilePhone,
			@RequestParam(value = "passWord", required = false) String passWord) {
		User user = new User(mobilePhone, passWord);
		user.setId(1);
		User u = userService.selectById(user);
		return resultData(ResultMsg.SUCCESS, u);
	}

}
